<?php

namespace app\common\model;

use think\Model;

class ReservationDateinfo extends Model
{

    // 表名
    protected $name = 'reservation_dateinfo';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
	// 追加属性
    protected $append = [
		'date_week',
		'timezone'
	];
	
	public function getDateWeekAttr($value, $data)
	{
		if($data['timetype'] == 1)
		{
			return $data['dateinfo'];
		}
		else
		{
			return $data['week'];
		}
	}
	
	public function getTimezoneAttr($value, $data)
	{
		return $data['starttime'].'至'.$data['endtime'];
	}
	
	public function reservation()
	{
		 return $this->belongsTo('Reservation', 'pid')->setEagerlyType(0);
	}

}
